import JSEncrypt from 'jsencrypt/bin/jsencrypt'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = `MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD70n2NfEh+FvmjZkRe+OeeN7pk
gG53jqyK/UdX2GggzUZfvVwFDPsJfbILsdknrE61P3E0L9C2WgenjE3wYr9jA4/g
P/PXKzapkrmL86AG0LYGi3EvzNMh9fFkJu7Hj9Jb8k1IDrSpmrnX6Dg5SKNloLoY
Pvqhz4dBJe/op7wEWQIDAQAB`;

const privateKey = `MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAPvSfY18SH4W+aNm
RF745543umSAbneOrIr9R1fYaCDNRl+9XAUM+wl9sgux2SesTrU/cTQv0LZaB6eM
TfBiv2MDj+A/89crNqmSuYvzoAbQtgaLcS/M0yH18WQm7seP0lvyTUgOtKmaudfo
ODlIo2Wguhg++qHPh0El7+invARZAgMBAAECgYA64bDx0EmzEfQ1PMhn3JNr72Pp
9A3gbr/xj9+KrtNKODVoVYKau7pHMdjb2y4HlMaior75kOSgftSjXK8ssipFqeWn
+OFNY0G3An8/Ze5swX0lEmkTKEhnYNR5vSgoRBiLq7Q5ZaWZ3Iv7kmk3ZVymHp2q
jfjJxdn+nJqD9xIWsQJBAP/6ea3NGPoHcoaTYAlPKWDLGmIYbL6yTQHgdTCpzoGh
0Ggu1emjpERE6xIf2O450oSg2IhIEz+lVR6odbUy5P8CQQD71+zpABTJJ9OcYgN3
rvle6a1JyXd0k19j/2IBIUP1yRtFsZKF1+Uo61WCJunmNLnhKgCBP/WPN9lXYaJd
jV6nAkEAvC40E6wqh2zAKeTf/hf/EFRfgev4zbwgVpffLzY2RSBjKKP9yDPwB+wu
b/WPsZo6hBwG8zEhTXHLAK3RUrMmmwJBAPsQOXfWwuH+ODEwbPCFmMiMAFsM429t
86zGzbb+qLeAcxW5fq67mhJ++VG05Xy/l4bmznYLgwvxy1QXWzwUUQUCQQCGzYD9
YEIaKzrJvUPtUdQ3d4Ia9YQySQskmjLjWtb5XZinp7VVgTNpZF39z93jr7Zk278n
5BHcrK4M+VI4/n+v`;


// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey);// 设置公钥
  return encryptor.encrypt(txt); // 对需要加密的数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPrivateKey(privateKey);
  return encryptor.decrypt(txt);
}
